package bavaria.hightec.testit;


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Proxy;

import bavaria.hightec.banking.*;
import bavaria.hightec.conditions.Conditions.runtime;
import bavaria.hightec.exceptions.OverCheckException;
import bavaria.hightec.exceptions.UnknownAccountException;
import bavaria.hightec.gui.BankCustomerLayout;
import bavaria.hightec.proxylogging.BankProxyInvocation;



public class ProxyTest {

    
    public static void main(String[] args) throws Exception {
        BankCustomerView bierbank = new BankImpl("Bierbank","EN");
        BankRegistry bankreg = BankRegistry.getInstance();
        bankreg.bind("Bierbank", (B2B) bierbank);
        BankProxyInvocation handler = new BankProxyInvocation(bierbank);
        
        // use the general Proxy class and an InvocationHandler based on reflection
        
        BankCustomerView bankproxy = (BankCustomerView) Proxy.newProxyInstance(
        		BankCustomerView.class.getClassLoader(),
                new Class[] { BankCustomerView.class },
                handler);
        testit(bankproxy);
    }
    
    
    public static void testit(BankCustomerView bank) throws OverCheckException, FileNotFoundException {
    	OutputStream out;
    	bank.createDepositAccount("Mustermann, Max",runtime.THREE);
        bank.createDepositAccount("Musterfrau, Max",runtime.SIX);
        bank.createDepositAccount("Muster, Max",runtime.THREE);
        bank.createDepositAccount("Mustermama, Max",runtime.TWELVE);
        new BankCustomerLayout(bank);
        Money money1 = new Money(10,Currency.EUR);
        Money money2 = new Money(100,Currency.EUR);
        Money money3 = new Money(1000,Currency.EUR);
        Money money4 = new Money(10000,Currency.EUR);
        Money money5 = new Money(100000,Currency.EUR);
        bank.fund(1001,money1,"so viel Geld!");
        bank.fund(1001,money2,"so ld!");
        bank.fund(1001,money3,"sGeld!");
        bank.fund(1001,money4,"sd!");
        bank.fund(1001,money5,"so viel!");
        out= new FileOutputStream("c:/users/mkaleja/java/Statement.txt");
        try {
			bank.statement(1001, out, "text/plain");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
        out= new FileOutputStream("c:/users/mkaleja/java/Statement.html");
        try {
			bank.statement(1001, out, "text/html");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
        try {
        try {
			bank.statement(1006, out, "text/html");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
        } catch (UnknownAccountException e){
        System.out.println(e.getMessage());
        }
    }
}

